import Vue from 'vue';
import Vuex from 'vuex';
import moduleA from './moduleA.js';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		count: 0,
		num: 1
	},
	mutations: {
		add (state) {
			state.count++;
		},
		addN (state, step) {
			state.count = state.count + step;
		},
		subN (state, step) {
			state.count = state.count - step;
		}
	},
	actions: {
		// 在Actions 中不能直接修改 state中的数据，要通过 mutations修改。
		addNAsync (context, step) {
			setTimeout(() => {
				context.commit('addN', step);
			});
		},
		subNAsync (context, step) {
			setTimeout(() => {
				context.commit('subN', step);
			});
		}
	},
	modules: {
		a: moduleA
	},
	getters: {
		showNum (state) {
			return '当前最新的数量是【' + state.count + '】';
		  }
	}
});
